<template>
  <div>    
      <!-- prop  绑定数据，最后渲染出来 -->
    <el-table :data="menuList" border style="width: 100%"  row-key="id" :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
      <el-table-column prop="id" label="菜单编号" width="180"></el-table-column>
      <el-table-column prop="title" label="菜单名称  " width="180"></el-table-column>
      <el-table-column prop="pid" label="上级菜单"></el-table-column>
      <el-table-column prop="icon" label="菜单图标" v-if="menuList.type==1"></el-table-column>
      <el-table-column prop="url" label="菜单地址" v-else></el-table-column>
      <el-table-column label="状态" width="100px">
        <!-- 不大懂 -->
        <template slot-scope="item">
          <div>
            <el-tag v-if="item.row.status==1" @click="abc(item)" type="success">启用</el-tag>
            <el-tag v-else type="danger">禁用</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="item"> 
          <div>                                            
                                                             <!-- 获取这一行的id -->
            <el-button type="primary"  size="mini" @click="edit(item.row.id)">编辑</el-button>
            <el-button type="danger" size="mini" icon="el-icon-delete" @click="del(item.row.id)">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { deleteMenu } from "../../util/axios";
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {};
  },
  components: {},
  methods: {
    ...mapActions({
      getMenuList: "menu/getMenuListAction"
    }),
    del(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          deleteMenu({ id }) //删除接口
            .then(res => {
              if (res.data.code == 200) {
               //重新调取菜单列表接口 重新渲染数据就好了              
               
                  this.getMenuList(); 
                   this.$message.success(res.data.msg);
                // console.log(res, "删除成功");
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    edit(id){
            this.$emit('edit',id)
    },
    abc(i){
      console.log(i);
    }
  },
  mounted() {
    this.getMenuList(); //第一次列表，删除后重新调取，重新渲染
  },
  computed: {
    ...mapGetters({
      menuList: "menu/getMenuList"
    })
  }
};
</script>

<style lang="" scoped>
</style>
